<br />
<div class="col-lg-9">
	<h1>Antenas</h1>  
</div>
<div class="col-lg-3 right">
	<br />
	<%= link_to 'Adicionar Nova Antena', new_antenna_path, class: 'btn btn-primary btn-block' %>  
</div>

<div class="content-panel">
	<table class="table table-striped table-advance table-hover">
  		<thead>
        	<tr>
        		<th>  </th>
            	<th> Descrição </th>
              	<th> Leitor </th>
              	<th> Porta (tx/rx) </th>
              	<th> Potência </th>
              	<th> Protocolo</th>
              	<th> Status </th>
              	<th>  </th>
          	</tr>
        </thead>
        <tbody id="sortable">
        	<% @antennas.each do |antenna| %>
        		<tr id="<%= antenna.ordenation %>">
        			<td><span class="fa fa-arrows"></span></td>
        			<td><%= antenna.description %></td>
        			<td><%= antenna.reader.description %></td>
        			<td><%= antenna.tx_rx_port %></td>
        			<td><%= antenna.power %></td>
        			<td><%= antenna.protocol %></td>
        			<td>
        				<%= '<span class="label label-success label-mini"> Ativo </span>'.html_safe if antenna.status %>
        				<%= '<span class="label label-warning label-mini"> Inativo </span>'.html_safe unless antenna.status %>
        			</td>
        			<td>
        				<%= link_to '<i class="fa fa-pencil"></i>'.html_safe, edit_antenna_path(antenna), class: 'btn btn-primary btn-xs' %>
        				<%= link_to '<i class="fa fa-trash-o "></i>'.html_safe, antenna_destroy_path(antenna), id: "delete-#{antenna.id}",  class: 'btn btn-danger btn-xs' %>
        				<script type="text/javascript">
							$(document).ready(function () {
								$("#delete-<%= antenna.id %>").click(function( e ){
								   if(!confirm('Você realmente deseja remover este registro?')) {
								      e.preventDefault();		      
								   }
								});
							});
						</script>
        			</td>
        		</tr>
    		<% end %>    	
        </tbody>
    </table>
</div>
<script type="text/javascript">
	$(function() {
	  $( "#sortable" ).sortable({
		  update: function( event, ui ) {
		  	var sortedIDs = $( "#sortable" ).sortable( "toArray" );
		  	$.post( "<%= antennas_order_path(format: :json) %>", { orders: sortedIDs })
		  		 .done(function() {
		  		 	window.location.href = "<%= antennas_path %>";
				  })
		  }
	  });
	});
</script>
